﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SignalR.Web.Models;
using System.Diagnostics;
using System.Security.Claims;

namespace SignalR.Web.Controllers
{

    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }
        [Authorize(Roles = "Admin")]
        public IActionResult Index()
        {
            ViewBag.UserName = HttpContext.User?.Identity?.Name;
            GetOnlineList();
            return View();
        }
        [Authorize(Roles = "SuperAdmin,Admin")]
		public IActionResult Privacy()
        {
            GetOnlineList();
            return View();
        }
 
        public void GetOnlineList()
        {
            var userList = WebConst.OnlineUserList;
            ViewBag.UserList = userList;
        }
        [HttpGet]
        public IEnumerable<OnlineUser> GetOnlineUser()
        {
            var userList = WebConst.OnlineUserList.ToArray();
            return userList;
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}